package com.sensePlusVR.main;

import java.util.Timer;
import java.util.TimerTask;

import org.xutils.x;
import org.xutils.view.annotation.ContentView;

import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.sensePlusVR.base.BaseActivity;
import com.sensePlusVR.utils.AppManager;
import com.sensePlusVR.utils.AppUtil;
import com.sensePlusVR.utils.PageJumpUtil;

@SuppressLint("HandlerLeak")
@ContentView(R.layout.introframe_land)
public class IntroFrameActivity extends BaseActivity {
	private static final int MSG_WHAT = 1;
	private static final int MSG_TIME_DELAY = 1000;
	private static final int MSG_TIME_PERIOD = 1000;
	private TextView countTime;
	private int curTime = 5;
	
	@Override
	public void setMyContentView() {
		x.view().inject(this);
	}
	
	@Override
	public void initView() {
		super.initView();
		
		AppManager.getInstance().addActivity(this);
		
		AppUtil.hideVirtualKey(this);
		
		countTime = (TextView) findViewById(R.id.countTime);

		timer.schedule(task, MSG_TIME_DELAY, MSG_TIME_PERIOD);
	}


	Handler handler = new Handler() {
		public void handleMessage(Message msg) {

			if (msg.what == MSG_WHAT) {

				countTime.setText(curTime + "s");

				curTime--;

				if (curTime == -1) {

					task.cancel();
					
					PageJumpUtil.JumpToRealGame(IntroFrameActivity.this);
					
					AppManager.getInstance().finishActivity();
					
				}

			}
		};
	};

	Timer timer = new Timer();

	TimerTask task = new TimerTask() {

		@Override
		public void run() {
			Message msg = new Message();
			msg.what = MSG_WHAT;
			handler.sendMessage(msg);
		}
	};

}
